﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPFTest
{
    public class TestDirectoryInfo
    {
        public TestDirectoryInfo(string path)
        {
            EnumFiles(path);
        }

        public DirectoryInfo Directory { get; private set; }



        ObservableCollection<TestDirectoryInfo> _Children = new ObservableCollection<TestDirectoryInfo>();
        public ObservableCollection<TestDirectoryInfo> Children { get { return _Children; } }

        //文件和目录列表
        ObservableCollection<FileSystemInfo> _SubFiles = new ObservableCollection<FileSystemInfo>();
        public ObservableCollection<FileSystemInfo> SubFiles { get { return _SubFiles; } }

        void EnumFiles(string path)
        {
            Directory = new DirectoryInfo(path);

            var dirs = Directory.EnumerateDirectories();
            foreach(var d in dirs)
            {
                _Children.Add(new TestDirectoryInfo(d.FullName));
                _SubFiles.Add(d);
            }

            var files = Directory.EnumerateFiles();
            foreach(var f in files)
            {
                _SubFiles.Add(f);
            }
        }
    }
}
